/** @file cardtest3.c
*   @brief Test mine_card
*/

#include "dominion.h"
#include "dominion_helpers.h"
#include <assert.h>
#include <stdio.h>
#include <limits.h>
int countCoins(int, struct gameState *);


int main(int argc, char **argv)
{
    // Mine card effects: trash 1 Treasure card from hand.
    //                    Gain a treasure card costing up to 3 more into hand.
    //                    choice1 is card to trash

    printf("Running tests for mine card.\n");

    int nPlayers = 2;
    int k[]      = {adventurer,
                    council_room,
                    feast,
                    gardens,
                    mine,
                    remodel,
                    smithy,
                    village,
                    baron,
                    great_hall
                   };
    int seed = 2;
    struct gameState g1;

    initializeGame(nPlayers, k, seed, &g1);



    int player  = 0;
    int card    = mine;
    int choice1 = 0;
    int choice2 = 0;
    int choice3 = 0;
    int handPos = 0;
    int bonus   = 0;


    g1.handCount[player] = 5;
    g1.hand[player][0] = mine;
    g1.hand[player][1] = smithy;
    g1.hand[player][2] = copper;
    g1.hand[player][3] = silver;
    g1.hand[player][4] = gold;
    int ncoins = countCoins(player, &g1);
    choice1 = 2;    // Treasure card to trash
    choice2 = silver; // Card to gain
    cardEffect(card, choice1, choice2, choice3, &g1, handPos, &bonus);
    assert (g1.handCount[player] == 4);
    assert(countCoins(player, &g1) == ncoins + 3 - 1);



    g1.handCount[player] = 5;
    g1.hand[player][0] = mine;
    g1.hand[player][1] = smithy;
    g1.hand[player][2] = copper;
    g1.hand[player][3] = silver;
    g1.hand[player][4] = gold;
    ncoins = countCoins(player, &g1);
    choice1 = 3;    // Treasure card to trash
    choice2 = gold; // Card to gain
    cardEffect(card, choice1, choice2, choice3, &g1, handPos, &bonus);
    assert (g1.handCount[player] == 4);
    assert(countCoins(player, &g1) == ncoins + 3 - 2);



    printf("Tests passed for mine card.\n");

}

int countCoins(int player, struct gameState *state)
{
    int sum = 0;
    for (int i = 0; i < state->handCount[player]; i++)
    {
        switch (state->hand[player][i])
        {
        case copper:
            sum += 1;
            break;
        case silver:
            sum += 2;
            break;
        case gold:
            sum += 3;
            break;
        }
    }
    return sum;
}
